//
//  HuaHereClass.m
//  HCFrame
//
//  Created by 丁 一 on 2018/6/12.
//  Copyright © 2018年 丁 一. All rights reserved.
//

#import "HuaHereClass.h"

@implementation HuaHereClass

+ (CGFloat)nav_height{
    CGFloat linheight = 64;
    if (RECERHEIGHT == 812.0000
        ||RECERHEIGHT == 896.0000) {
        linheight = 88.0000;
    }
    return linheight;
}

+ (NSString *)Spacenull:(NSString *)Space{
    if (Space) {
        return Space;
    }else{
        return @"";
    }
}

+ (CGSize)size:(NSString *)text font:(UIFont *)font width:(CGFloat)width height:(CGFloat)height{
    if (!text) {
        return CGSizeMake(0, 0 );
    }
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    CGSize size = [text boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size;
}

/*
 m:月份
 d:日期
 */
+(NSString *)getAstroWith:(NSString *)date{
    
    NSArray  *array = [date componentsSeparatedByString:@"-"];
    
    if (array.count<3) {
        return @"日期格式有误";
    }
    
    int m = [[array objectAtIndex:1] intValue];
    int d = [[array objectAtIndex:2] intValue];
    
    NSString *astroString = @"魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯";
    NSString *astroFormat = @"102123444543";
    NSString *result;
    if (m<1||m>12||d<1||d>31){
        
        return @"日期格式有误";
    }
    if(m==2 && d>29){
        return @"错误日期格式!!";
    }
    else if(m==4 || m==6 || m==9 || m==11) {
        
        if (d>30) {
            return @"错误日期格式!!!";
            
        }
        
    }
    
    result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(m*2-(d < [[astroFormat substringWithRange:NSMakeRange((m-1), 1)] intValue] - (-19))*2,2)]];
    
    return result;
    
}

+(UIColor *)getcolorx:(NSString *)date{
    NSArray  *array = [date componentsSeparatedByString:@"-"];
    if (array.count<3) {
        return [UIColor blackColor];
    }
    
    int m = [[array objectAtIndex:1] intValue];
    int d = [[array objectAtIndex:2] intValue];
    
    NSString *astroString = @"01020304050607080910111201";
    NSString *astroFormat = @"102123444543";
    NSString *result;
    if (m<1||m>12||d<1||d>31){
        
        return [UIColor blackColor];
    }
    if(m==2 && d>29){
        return [UIColor blackColor];
    }
    else if(m==4 || m==6 || m==9 || m==11) {
        
        if (d>30) {
            return [UIColor blackColor];
            
        }
        
    }
    
    result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(m*2-(d < [[astroFormat substringWithRange:NSMakeRange((m-1), 1)] intValue] - (-19))*2,2)]];
    
    int indexs = [result intValue];
    
    NSArray *colorarray = @[@"#4a98e1",@"#83d6e3",@"#f2df75",@"#ee6250",@"#5abff6",@"#f39d49",@"#82827c",@"#f6b941",@"#9bc254",@"#d15fa9",@"#a15ac7",@"#99db8b"];
    
    return [JonesClass stringTOColor:[colorarray objectAtIndex:indexs]];
}

+ (NSArray *)getfeeling{
    return @[@"长期空窗",@"单身ing",@"恋爱ing",@"热恋ing",@"已婚",@"离异",@"丧偶",@"保密"];
}

+ (NSString *)getindex:(BOOL)index name:(NSString *)name{
    
    __block NSString *fanhuistr = @"";
    
    if (index) {
        
        [[HuaHereClass getfeeling] enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj isEqualToString:name]) {
                
                fanhuistr = [NSString stringWithFormat:@"%lu",(unsigned long)idx];
                
                *stop = YES;
            }
        }];
        
        return fanhuistr;
    }else{
        
        if ([name intValue]>7) {
            return @"";
        }
        
        return [[HuaHereClass getfeeling] objectAtIndex:[name intValue]];
    }
    
}

+ (NSString *)chuliheight:(NSString *)height{
    
    if (!height) {
        return @"";
    }
    if ([height isEqualToString:@""]) {
        return @"";
    }
    
    NSArray *linarray = [height componentsSeparatedByString:@" "];
    return [linarray objectAtIndex:0];
}

+ (NSArray *)get_logo_array:(NSString *)listlogo{
    if (listlogo&&![listlogo isEqualToString:@""]) {
        if ([listlogo rangeOfString:@"&&"].location == NSNotFound) {
            return @[listlogo];
        } else {
            NSMutableArray *linarray = [NSMutableArray new];
            NSArray  *array = [listlogo componentsSeparatedByString:@"&&"];
            [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [linarray addObject:obj];
            }];
            return [linarray copy];
        }
    }else{
        return @[];
    }
}

+(BOOL)checkiphone:(NSString  *)_text{
    //手机号
    NSString * MOBILE = @"^1(3[0-9]|4[0-9]|6[0-9]|7[0-9]|9[0-9]|5[0-9]|8[0-9])\\d{8}$";
    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    
    if (([regextestmobile evaluateWithObject:_text] == YES)
        || ([regextestcm evaluateWithObject:_text] == YES)
        || ([regextestct evaluateWithObject:_text] == YES)
        || ([regextestcu evaluateWithObject:_text] == YES)){
        return YES;
    }else{
        return NO;
    }
}

@end
